package Java.com.wang.Three;

public  class Queue2Stack {

    sequenceQueue<Integer> q1 = new sequenceQueue<Integer>();
    sequenceQueue<Integer> q2 = new sequenceQueue<Integer>();
    int a[] = {1, 2, 3, 4, 5, 6};

    public static void main(String[] args) {

        Queue2Stack queue2Stack = new Queue2Stack();
        int j = 0;

        //push
        for (int i = 0; i <= queue2Stack.a.length - 1; i++) {
            queue2Stack.q1.EnQueue(queue2Stack.a[i]);
        }
        queue2Stack.q1.EnQueue(queue2Stack.a[queue2Stack.a.length-1]);

        System.out.println("列表内现有元素:");
        queue2Stack.q1.nextOrder();

        //pop
        for (j = 0; j < queue2Stack.a.length; j++) {
            if ((j % 2 == 1) ) {
                for (int i = 0; i <= queue2Stack.q2.size()+1; i++) {
                    queue2Stack.q1.EnQueue(queue2Stack.q2.GetTop());
                    queue2Stack.q2.DeQueue();
                }
                System.out.println("取出元素为：" + queue2Stack.q2.GetTop());
            }
            else {
                for (int i = 0; i <=queue2Stack.q1.size()+1; i++) {
                    queue2Stack.q2.EnQueue(queue2Stack.q1.GetTop());
                    queue2Stack.q1.DeQueue();
                }
                System.out.println("取出元素为：" + queue2Stack.q1.GetTop());
                queue2Stack.q1.DeQueue();
            }
        }
    }
}



